import React, { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

const WXCallback = () => {
    const location = useLocation();

    useEffect(() => {
        const params = new URLSearchParams(location.search);
        const code = params.get('code');
        // const state = params.get('state');

        if (code) {
            // 将授权码发送回父窗口
            window.opener.postMessage({ type: 'WX_LOGIN_CODE', code }, '*');
            window.close();
        } else {
            console.error('未获取到授权码');
            window.close();
        }
    }, [location]);

    return (
        <div style={{ 
            display: 'flex', 
            justifyContent: 'center', 
            alignItems: 'center', 
            height: '100vh',
            fontSize: '16px'
        }}>
            正在处理微信登录...
        </div>
    );
};

export default WXCallback; 